home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / PCGEN.ASM < prev    next >
Assembly Source File  |  1990-08-01  |  4KB  |  244 lines

  1.     NAME pcgen
  2.     include    pmacros.h
  3.  
  4. dseg
  5. pubvar    mtasker,<db ?>
  6. dsegend
  7.  
  8. if TURBO
  9. else
  10. ; setvect - set interrupt vector
  11. ; called from C as follows
  12. ; setvect(vec,vecval)
  13. ; char vec;        /* Interrupt number */
  14. ; void (*vecval)();    /* offset (and segment in large code model) */
  15.  
  16.     procdef    setvect,<<vec,byte>,<ipval,fptr>>
  17.     mov    ah,25h
  18.     mov    al,vec
  19.     push    ds        ; save
  20. ifdef    LARGECODE
  21.     lds    dx,ipval
  22. else
  23.     mov    dx,ipval
  24.     push    cs
  25.     pop    ds
  26. endif
  27.     int    21h
  28.     pop    ds        ; restore
  29.     pret
  30.     pend    setvect
  31.  
  32. ; getvect - return current interrupt vector
  33. ; called from C as
  34. ; long        /* Returns CS in high word, IP in low word */
  35. ; getvect(vecnum)
  36. ; char vecnum;    /* Interrupt number */
  37.  
  38.     procdef    getvect,<<vecnum,byte>>
  39.     mov    ah,35h
  40.     mov    al,vecnum
  41.     push    es    ; save, since DOS uses it for a return value
  42.     int    21h
  43.     mov    dx,es    ; CS value into DX (C high word)
  44.     mov    ax,bx    ; IP value into AX (C low word)
  45.     pop    es    ; restore es
  46.     pret
  47.     pend    getvect
  48. endif
  49.  
  50. ; kbraw - raw, nonblocking read from console
  51. ; If character is ready, return it; if not, return -1
  52.  
  53.     procdef kbraw
  54.     mov    ah,06h    ; Direct Console I/O
  55.     mov    dl,0ffh ; Read from keyboard
  56.     int    21h    ; Call DOS
  57.     jz    nochar    ; zero flag set -> no character ready
  58.     mov    ah,0    ; valid char is 0-255
  59.     pret
  60. nochar:
  61.     mov    ax,-1    ; no char, return -1
  62.     pret
  63.     pend    kbraw
  64.  
  65. ; disable - disable interrupts and return previous state: 0 = disabled,
  66. ;           1 = enabled
  67.  
  68.  if    TURBO
  69.     procdef    Disable
  70.  else
  71.     procdef    disable
  72.  endif
  73.     pushf            ; save state on stack
  74.     cli            ; interrupts off
  75.     pop    ax        ; original flags -> ax
  76.     and    ax,200h        ; 1<<9 is IF bit
  77.     jnz    ion        ; nonzero -> interrupts were on
  78.     pret
  79. ion:    mov    ax,1
  80.     pret
  81.  if    TURBO
  82.     pend    Disable
  83.  else
  84.     pend    disable
  85.  endif
  86.  
  87. ; restore - restore interrupt state: 0 = off, nonzero = on
  88.  
  89.     procdef    restore,<<istate,byte>>
  90.     test    istate,0ffh
  91.     jz    ioff
  92.     sti
  93. ioff:    pret
  94.     pend    restore
  95.  
  96. ; Halt until an interrupt occurs, then return
  97.     procdef eihalt
  98.     sti    ; make sure interrupts are enabled
  99.     hlt
  100.     pret
  101.     pend    eihalt
  102.  
  103. ; multitasker types
  104. NONE        equ    0
  105. DOUBLEDOS    equ    1
  106. DESQVIEW    equ    2
  107.  
  108. ; Relinquish processor so other task can run
  109.     procdef    giveup
  110.     cmp    mtasker@,DOUBLEDOS
  111.     jnz    givedesqview
  112.     mov    al,2        ; 110 ms
  113.     mov    ah,0eeh
  114.     int    21h
  115.  
  116. givedesqview:
  117.     cmp    mtasker@,DESQVIEW
  118.     jnz    notask
  119.     mov    ax,1000h
  120.     int    15h
  121. notask:
  122.     pret
  123.     pend    giveup
  124.  
  125. ; check for a multitasker running
  126.     procdef chktasker
  127.     mov    mtasker@,NONE
  128.     ; do the doubledos test
  129.     mov    ah,0e4h
  130.     int    21h
  131.     cmp    al,1
  132.     jz    isdos
  133.     cmp    al,2
  134.     jnz    test_desq
  135. isdos:    mov    mtasker@,DOUBLEDOS
  136.     pret
  137.  
  138.     ; test for desqview
  139. test_desq:
  140.     mov    ax,2b01h
  141.     mov    cx,4445h
  142.     mov    dx,5351h
  143.     int    21h
  144.     cmp    al,0ffh
  145.     jnz    isdesq
  146.     pret
  147. isdesq:    mov    mtasker@,DESQVIEW
  148.     pret
  149.     pend    chktasker
  150.  
  151. ; getds - Read DS for debugging purposes
  152.     procdef    getds
  153.     getds
  154.     pret
  155.     pend    getds
  156. ;
  157. ; dos service routine used by JK1NNT installed by N3EUA
  158. ;
  159.  
  160.     procdef    jkintdos,<<reg_a,word>,<reg_b,word>,<reg_d,word>>
  161.     mov    ax,reg_a
  162.     mov    bx,reg_b
  163.     mov    dx,reg_d
  164.     int    21h
  165.     pret
  166.     pend    jkintdos
  167. ;
  168. ; NEC PC-9801 speed setting routine by JK1NNT installed by N3EUA
  169. ;
  170.     procdef    set_speed,<<s_code,word>>
  171.     push    ds
  172.     mov    ax,40h
  173.     mov    ds,ax
  174.     mov    dx,s_code
  175.     mov    ds:[269h],dl
  176.     mov    dh,4ch
  177.     mov    ds:[268h],dh
  178.     pop    ds
  179.     mov    cl,0ah
  180.     int    0dch
  181.     pret
  182.     pend    set_speed
  183.  
  184. ;
  185. ; This routine is a generic int 21h handler, is used only by disk free
  186. ; routine.  Added by K3MC  3 Dec 87
  187. ;
  188. ;
  189. ; General-purpose int 21h caller, currently used only to return AX, BX, CX, DX
  190. ; for computing amount of free disk space, and amount of total disk space.
  191. ;
  192. ; declared as: void isfree();
  193. ;
  194. ; Called from C as:
  195. ;
  196. ; isfree(&ax,&bx,&cx,&dx)
  197. ; unsigned short ax,bx,cx,dx;
  198. ;
  199.     procdef    isfree,<<c_ax,ptr>,<c_bx,ptr>,<c_cx,ptr>,<c_dx,ptr>>
  200.     push    ax
  201.     push    bx
  202.     push    cx
  203.     push    dx
  204.     push    bp
  205.     push    si
  206.     push    di
  207.     pushds
  208.     ldptr    di,c_ax,ds
  209.     mov    ax,[di]
  210.     ldptr    di,c_bx,ds
  211.     mov    bx,[di]
  212.     ldptr    di,c_cx,ds
  213.     mov    cx,[di]
  214.     ldptr    di,c_dx,ds
  215.     mov    dx,[di]
  216.     int     21h
  217.     ldptr    di,c_ax,ds
  218.     mov    [di],ax
  219.     ldptr    di,c_bx,ds
  220.     mov    [di],bx
  221.     ldptr    di,c_cx,ds
  222.     mov    [di],cx
  223.     ldptr    di,c_dx,ds
  224.     mov    [di],dx
  225.     popds
  226.     pop    di
  227.     pop    si
  228.     pop    bp
  229.     pop    dx
  230.     pop    cx
  231.     pop    bx
  232.     pop    ax
  233.     pret
  234.     pend    isfree
  235.  
  236. ; Return 03 in AL to fail a critical error
  237.  
  238.     pubproc    crit_hdl
  239.     mov    al,3
  240.     iret
  241.     pend    crit_hdl
  242.  
  243.     end
  244.